package test.raytracer;

public final class WorldBYG {

    public VirtualScreen DivideAndConquer(int x, int y, int w, int h, World world){

	if (w == 1 && h == 1) {
	    GfxColor c = world.GetPixelGfxColor(x - world.mx, y - world.my);
	    VirtualScreen ret = new VirtualScreen(c);
	    return ret;
	}
	int nw = w / 2;
	int nh = h / 2;

	if (nw == 0) {
	    nw = 1;
	}
	if (nh == 0) {
	    nh = 1;
	}

	VirtualScreen result = new VirtualScreen(w, h);

	VirtualScreen sub1;
	VirtualScreen sub2;
	VirtualScreen sub3;
	VirtualScreen sub4;
	int newX = x + nw;
	int newY = y + nh;
	sub1 = this.DivideAndConquer(x, y, nw, nh, world); /* new job */
	sub2 = this.DivideAndConquer(newX, y, nw, nh, world); /* new job */
	sub3 = this.DivideAndConquer(x, newY, nw, nh, world); /* new job */
	sub4 = this.DivideAndConquer(newX, newY, nw, nh, world); /* new job */

	result.Set(0, 0, nw, nh, sub1);
	result.Set(nw, 0, nw, nh, sub2);
	result.Set(0, nh, nw, nh, sub3);
	result.Set(nw, nh, nw, nh, sub4);

	return result;
    }
}
